addons/namingng.py: Add tests for include guards, config file validation.#5815
Conversation
Include guard naming can be validated against various patterns: - prefixes/suffixes (_FILE_H, PROJECT_FILE_H, FILE_H_) - basename/full path (FILE_H, SUB_DIR_INC_FILE_H) - upper- or lowercase (FILE_H, file_h) or case kept as-is (File_h) - any combination of the above (project_sub_dir_inc_file_h_) A regexp can be specified to match header filenames. The default matches any filename not starting with / and ending with .h, intended to match C header files while exluding system files. The check is not limited to naming only; validity and presence of include guards can also be tested by setting "required":true in the config file. Enabling this feature requires adding the key "include_guard" to the namingng config file. The namingng unit test is extended to test various features of the include guard check.
The config file is parsed and (superficially) validated, before starting validation. Various errors are checked and reported, along with a non-zero exit status. After parsing and type validation, the config values are stored in an object, so they can be referenced as object members instead of dict keys (`conf.variable` instead of `conf["RE_VARNAME"]`). This separates config syntax from application code. A unit test is added to test config file validation. The example config JSON in namingng.py is fixed.
danmar
left a comment
There was a problem hiding this comment.
lgtm.. if you feel satisfied we can merge this..
Great. I cannot think of anything else to add or improve - it was used to clean up a medium-sized project already. |
|
Any behavior (breaking) changes, new features and fixes should be documented in Also the addon should be documented in We (including external contributors) have been rather lax at both in the past and we (at least me) try to be more strict on this nowadays. |
Sounds good. I will prepare a pull request, addressing:
|
Include guard naming can be validated against various patterns:
_FILE_H,PROJECT_FILE_H,FILE_H_)FILE_H,SUB_DIR_INC_FILE_H)FILE_H,file_h)project_sub_dir_inc_file_h_)A regexp can be specified to match header filenames. The example matches any filename not starting with / and ending with
.h, intended to match C header files while exluding system files.The test is not limited to naming only; validity and presence of include guards can also be tested by setting
"required":truein the config file.Enabling this feature requires adding the key
"include_guard"to the namingng config file used.The namingng unit test is extended to test various features of the include guard test.
Also, config handling is improved, adding (superficial) validation and a unit test.